package com.das.mechanic_webview.view.report;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.das.mechanic_base.R2;
import com.das.mechanic_base.base.X3BaseActivity;
import com.das.mechanic_base.base.X3BasePresenter;
import com.das.mechanic_base.bean.task.AloneShareParamsBean;
import com.das.mechanic_base.utils.X3FileUtils;
import com.das.mechanic_base.utils.X3StatusBarUtil;
import com.das.mechanic_base.utils.X3ToastUtils;
import com.das.mechanic_base.widget.X3BottomShareDialog;
import com.das.mechanic_base.widget.X3MemberButtonView;
import com.das.mechanic_webview.R;

import java.io.File;

import butterknife.BindView;
import butterknife.OnClick;

public class X3ReportActivity extends X3BaseActivity implements X3MemberButtonView.IOnClickAffirm {

    @BindView(R2.id.rl_header)
    RelativeLayout rl_header;
    @BindView(R2.id.mv_btn)
    X3MemberButtonView mv_btn;
    @BindView(R2.id.iv_icon)
    ImageView iv_icon;
    @BindView(R2.id.fl_back)
    FrameLayout fl_back;
    private String path;

    AloneShareParamsBean aloneShareParamsBean;

    @Override
    protected int getLayoutId() {
        return R.layout.x3_activity_report;
    }

    @Override
    protected void initView() {

        this.getWindow().getDecorView().setBackgroundColor(Color.parseColor("#99000000"));

        setSwipeBackEnable(false);

        X3StatusBarUtil.darkMode(this);


//        X3StatusBarUtil.darkMode(this,false);
        rl_header.setPadding(0, X3StatusBarUtil.getStatusBarHeight(this),0,0);

        path = getIntent().getStringExtra("path");
        aloneShareParamsBean = getIntent().getParcelableExtra("aloneShareBean");

        mv_btn.changeText(getString(R.string.save_large_image));
        Glide.with(this).load(path).apply(new RequestOptions().override(Target.SIZE_ORIGINAL)).into(iv_icon);
        mv_btn.changeBtnStatus(true);
        mv_btn.setiOnClickAffirm(this);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                X3BottomShareDialog dialog = new X3BottomShareDialog(X3ReportActivity.this,X3ReportActivity.this,path);
                dialog.aloneShareParamsBean = aloneShareParamsBean;
                dialog.show();
            }
        },200);
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    Handler handler = new Handler();

    @Override
    protected X3BasePresenter createPresenter() {
        return null;
    }

    @Override
    public boolean isTransparent(){
        return  true;
    }

    @OnClick({R2.id.iv_back,R2.id.fl_back})
    public void onViewClick(View view) {
        if (view.getId() == R.id.iv_back || view.getId() == R.id.fl_back) {
            finish();
        }
    }

    @Override
    public void iOnClickAffirm() {
        Bitmap bitmap = BitmapFactory.decodeFile(path);
        File file = new File(path);
        X3FileUtils.saveBitmapToCamera(this,file.getName() + ".jpg",bitmap);
        X3ToastUtils.showMessage(getString(R.string.x3_keep_success));
        finish();
    }

    @Override
    public void finish() {
        super.finish();
//        this.overridePendingTransition(0,R.anim.activity_top_exit);
        this.overridePendingTransition(0,R.anim.alpha_out2);
    }
}